<!--#include file="functions.asp" -->
<%
  dim EmailBody, rs, sql, sqlsub, rssub, sRecipientName, sRecipient, EmailSubject, EmailConf
  dim FieldConf

  response.Write("<p><b>Sending Status :</b></p>")
  sql = "SELECT EMPCODE, LOGINNAME, MANAGERNAME, ISNULL(DOATO,'') AS DOACODE, DOANAME, DEPARTMENT, "
  sql = sql & "ISNULL((SELECT EMAIL FROM EMP WHERE EMPCODE=DOATO), '') AS DOAEMAIL FROM EXIAUTHORITY"
  set rs=cn.execute(sql)
  do until rs.eof
    set rssub = cn.execute("EXIOUTSTANDING '" & rs("DEPARTMENT") & "'")
	if not rssub.eof then
	  'Set Subject
	  EmailSubject = "Outstanding " & rs("DEPARTMENT") & " Invoices Notification " & ezformatdate("MMM dd, yyyy", Now)
	  'Set recipient name and email
	  if rs("DOAEMAIL") <> "" then 
	    sRecipientName = rs("DOANAME")
		sRecipient = rs("DOAEMAIL")
	  else
	    sRecipientName = rs("MANAGERNAME")
		sRecipient = rs("LOGINNAME") & "@" & emailDomain
	  end if
	  EmailBody = "<div style='font-family: Arial;font-size: 9pt;color:Black;background-color:#D4D2C2;padding: 10px 10px 10px 10px;border:1px solid Gray;'>Dear " & sRecipientName & ","
	  EmailBody = EmailBody & "<p><span style='font-size:8pt'><em>Please do not reply this e-mail. This e-mail was auto generated by Electronic Invoice Approval System.</em></span></p>"
	  EmailBody = EmailBody & "<p>This is the summary  status of outstanding invoice(s) for your department as of " & ezformatdate("MMM dd, yyyy", Now) & ".</p>"
	  EmailBody = EmailBody & "<table border='0' cellspacing='0' cellpadding='5' style='font-family:Arial;font-size:9pt;background-color:#D4D2C2;'>"
	  rssub.MoveNext
	  do until rssub.eof ' Let us get the details
	    select case rssub("counttype")
		  case 1
            EmailBody = EmailBody & "<tr><td width='10'><b style='color:Red'>RED</b></td><td width='3'>:</td><td>" & rssub("countnumber") & "</td><td style='font-size:9pt'><em>invoice is being processed for approval in more than 14 days</em></td></tr>"
		  case 2
            EmailBody = EmailBody & "<tr><td width='10'><b style='color:Yellow'>YELLOW</b></td><td width='3'>:</td><td>" & rssub("countnumber") & "</td><td style='font-size:9pt'><em>invoice is being processed for approval within 7 - 14 days</em></td></tr>"
		  case 3
            EmailBody = EmailBody & "<tr><td width='10'><b style='color:Green'>GREEN</b></td><td width='3'>:</td><td>" & rssub("countnumber") & "</td><td style='font-size:9pt'><em>invoice is being processed for approval within 3 - 7 days</em></td></tr>"
		  case 4
            EmailBody = EmailBody & "<tr><td width='10'><b style='color:White'>WHITE</b></td><td width='3'>:</td><td>" & rssub("countnumber") & "</td><td style='font-size:9pt'><em>invoice is being processed for approval in less than 3 days</em></td></tr>"
		end select
	    rssub.MoveNext
	  loop
	  set rssub = nothing
	  EmailBody = EmailBody & "</table><br>&nbsp;<br>"
	  EmailBody = EmailBody & "<p>Click following URL to view the oustanding invoices or copy and paste it to your browser: <a href='" & theurl & "/outstanding_dept.asp'>" & theurl & "/outstanding_dept.asp</a></p>"
	  EmailBody = EmailBody & "<p>Thank you for your kind cooperation.</p><p>Finance Department</p></div>"

      SendCDOEmail sRecipient, "BKoernianto@premier-oil.com", "", "Finance_Department", EmailSubject, EmailBody
      Response.Write(sRecipientName & " &#8249;" & sRecipient & "&#8250; sent.<br>")
	end if
    rs.MoveNext	
  loop
%>
<p><b>Sending complete! <a href="outstanding_inv.asp?type=<%= request("type") %>">Click to continue</a>.</b></p>
